package com.centling.smartSealForPhone.db;

import com.centling.smartSealForPhone.constants.UrlConstants;
import com.centling.smartSealForPhone.utils.LogUtil;
import com.centling.smartSealForPhone.utils.OkHttpUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author monkey
 * @date 16-12-5
 */

public class UpWarnInfo {

    private static UpWarnInfo warnInfo;

    public static UpWarnInfo getInstance() {
        if (warnInfo == null) {
            synchronized (UpWarnInfo.class) {
                if (warnInfo == null) {
                    warnInfo = new UpWarnInfo();
                }
            }
        }
        return warnInfo;
    }

    public static void upgrandWarnInfo() {
        List<WarnBean> warnList = DbControl.getInstance().selectWarningData();
        if (warnList.size() > 0) {
            LogUtil.d("--------------------size:" + warnList.size());
            for (int j = 0; j < warnList.size(); j++) {
                final WarnBean warnBean = warnList.get(j);
                Map<String, String> param = new HashMap<>();
                final String warnId = warnList.get(j).getProcessId();
                param.put(DbConstance.PROCESSFLAG, warnBean.getProcessFlag());
                param.put(DbConstance.PROCESSID, warnBean.getProcessId());
                param.put(DbConstance.ALARMMSG, warnBean.getAlarmMsg());
                param.put(DbConstance.LATITUDE, warnBean.getLatitude());
                param.put(DbConstance.LONGTITUDE, warnBean.getLongitude());
                param.put(DbConstance.ALARMLOACATION, warnBean.getAlarmLocation());
                param.put(DbConstance.COMPANY_CODE, warnBean.getCompanyCode());
                OkHttpUtil.postJsonEnqueue(UrlConstants.STAMP_ALERT, param, new OkHttpUtil.NetCallBack() {
                    @Override
                    public void onSucceed(String json) {
                        DbControl.getInstance().deleteWarnData(warnId);
                    }

                    @Override
                    public void onFailed(String reason) {

                    }
                }, "OKHttpCallBack");
            }
        }
    }
}
